package com.gamerole.app.ui

import androidx.appcompat.widget.SearchView.OnQueryTextListener
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.MutableLiveData
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.gamerole.app.R
import com.gamerole.app.databinding.AppFragmentAlipanBinding
import com.gamerole.app.databinding.AppFragmentChatBinding
import com.gamerole.app.entity.ArticleBean
import com.gamerole.app.entity.bus.PanSearchEvent
import com.gamerole.app.viewmodel.AliPanViewModel
import com.gamerole.app.viewmodel.ChatViewModel
import com.gamerole.commom.adapter.MyFragmentPagerAdapter
import com.gamerole.commom.base.BaseFragment
import com.gamerole.commom.extention.click
import com.google.android.material.tabs.TabLayoutMediator
import com.hi.dhl.binding.viewbind
import com.jansir.eventbus.Kobus
import dagger.hilt.android.AndroidEntryPoint
import java.util.*


@AndroidEntryPoint
class AliPanFragment : BaseFragment(R.layout.app_fragment_alipan) {
    private val viewModelChat: AliPanViewModel by viewModels()
    override fun getViewModel() = viewModelChat
    private val binding: AppFragmentAlipanBinding by viewbind()

//    override fun initStatusNavBar() {
//        ImmersionBar.with(this)
//            .fitsSystemWindows(false)
//            .fullScreen(true)
//            .transparentNavigationBar()
//            .init()
//    }

    override fun initData() {

    }

    override fun initView() {
        var fragments = ArrayList<Fragment>()

        fragments.add(UpSearchFragment())


        binding.viewPager.offscreenPageLimit = 1
        binding.viewPager.adapter = object : FragmentStateAdapter(childFragmentManager, lifecycle) {
            override fun getItemCount(): Int {
                return fragments.size
            }

            override fun createFragment(position: Int): Fragment {
                return fragments[position]
            }
        }
        var titles = arrayListOf("UP云搜")
        TabLayoutMediator(binding.tabLayout, binding.viewPager) { tab, position ->
            tab.text = titles[position]
        }.attach()
    }

    override fun initEvent() {
        binding.apply {
            searchView.setOnQueryTextListener(object : OnQueryTextListener {
                override fun onQueryTextSubmit(query: String?): Boolean {
                    if (query != null) {
                        Kobus.post(PanSearchEvent(query))
                    }
                    return true
                }

                override fun onQueryTextChange(newText: String?): Boolean {
                    return false
                }
            })
        }
    }


}